import React from 'react'
import { renderToString } from 'react-dom/server'
import { Provider } from 'react-redux'
import { Router, Route, hashHistory } from 'react-router'
import structureStore from '../../store/createStore'

import Login from './components/login.jsx'
import reducer from './modules/login'

import Navigation from '../../common/Navigation/navigation.jsx'
import navReducer from '../../common/Navigation/reducer'

const routeNodes = (params, initState) => {
  let store = structureStore(params, initState, {
    params: () => params,
    layoutState: reducer,
    navigation: navReducer
  })

  if (params.renderType === 'client') {
    return (
      <Provider store={store}>
        <Router history={hashHistory} >
          <Route path='/' component={Login} />
          <Route path='/nav' component={Navigation} />
        </Router>
      </Provider>
    )
  } else {
    return renderToString(
      <Provider store={store}>
        <Login />
      </Provider>
    )
  }
}

export default routeNodes
